

<template>
  <div>
    <t-space direction="vertical" size="small" class="t-progress-domo-width" style="width: 100%">
      <div class="t-progress-domo-margin">{{message}}</div>
      <t-progress theme="plump" :status="status" :percentage="progress" />
      <t-link v-if="zipUrl" theme="primary"  :href="zipUrl" target="_blank">
        <template #prefix-icon>
          <link-icon />
        </template>
        视频打包完成,点击下载
      </t-link>
    </t-space>
</div>
</template>
<script setup>
import { ref,onUnmounted } from 'vue';
import {post,get} from "@/utils/api";
import config from "@/config";
import {LinkIcon} from "tdesign-icons-vue-next";
// eslint-disable-next-line vue/no-setup-props-destructure
const { item } = defineProps({
  item: {
    type: Object,
    required: true,
  },
});
console.log("item",item)

const zipUrl = ref("");
const progress = ref(0);
const message = ref("");
const status = ref("");
const timer_progress = ref(null)
timer_progress.value =setInterval(() => {
  getProgress(item.code)
}, 500);
const getProgress = (code)=>{
  post(config.queueProgress,{code:code}).then(res=>{
    if(res.data.code===1){
      progress.value = res.data.data.progress;
      message.value = res.data.data.message;
      let queue_status = res.data.data.status;
      switch (queue_status) {
        case 4:
          status.value = "error";
          clearInterval(timer_progress.value);
          break;
        case 1:
          status.value = "active";
          break;
        case 2:
          status.value = "active";
          break;
        case 3:
          status.value = "success";
          clearInterval(timer_progress.value);
          getVideoZipUrl();
          break;
        default:
          status.value = "default";
      }
    }else{
      clearInterval(timer_progress.value);
    }
  })
}
const getVideoZipUrl = () =>{
  get(config.getVideoZipUrl,{
    task_id:item.task_id,
    task_run_log_id:item.task_run_log_id
  }).then(res=>{
    if(res.data.code===1){
      zipUrl.value = res.data.data;
    }
  })
}
onUnmounted(()=>{
  clearInterval(timer_progress.value);
})

</script>
<style scoped>

</style>
